using System;
using System.Collections.Generic;
using System.Text;
using ECommerce.DAL;
using System.Data.SqlClient;
using System.Data;

namespace Entity
{
    [System.ComponentModel.DataObject]
    public class TblProductStockExtended : TblProductStock
    {
        public static CustomCollection<TblProductStock> GetProductStockByProductId(int productId)
        {
            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@ProductId", SqlDbType.Int, 0, ParameterDirection.Input, productId);

            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBL_PRODUCTSTOCK_GET_PRODUCT_STOCK_BY_PRODUCTID);
            GenerateCollectionFromReader reader = new GenerateCollectionFromReader(GenerateTblProductStockCollectionFromReader);
            CustomCollection<TblProductStock> objCollection = ((CustomCollection<TblProductStock>)ExecuteReaderCmd(sqlCmd, reader));

            return objCollection;
        }

        public static CustomCollection<TblProductStock> GetStockOutItems(int stockLevel)
        {
            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@StockLevel", SqlDbType.Int, 0, ParameterDirection.Input, stockLevel);

            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBL_PRODUCTSTOCK_GET_PRODUCT_STOCK_BY_STOCK_LEVEL);
            GenerateCollectionFromReader reader = new GenerateCollectionFromReader(GenerateTblProductStockCollectionFromReader);
            CustomCollection<TblProductStock> objCollection = ((CustomCollection<TblProductStock>)ExecuteReaderCmd(sqlCmd, reader));

            return objCollection;
        }


        public static CustomCollection<TblProductStock> GetStockOutItemsPaged(int stockLevel,string orderBy, int startRow, int pageSize)
        {
            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@StockLevel", SqlDbType.Int, 0, ParameterDirection.Input, stockLevel);
            AddParameterToSqlCmd(sqlCmd, "@orderby", SqlDbType.VarChar, 50, ParameterDirection.Input, orderBy);
            AddParameterToSqlCmd(sqlCmd, "@startrow", SqlDbType.Int, 0, ParameterDirection.Input, startRow);
            AddParameterToSqlCmd(sqlCmd, "@pagesize", SqlDbType.Int, 0, ParameterDirection.Input, pageSize);

            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBL_PRODUCTSTOCK_GET_PRODUCT_STOCK_BY_STOCK_LEVELPAGED);
            GenerateCollectionFromReader reader = new GenerateCollectionFromReader(GenerateTblProductStockCollectionFromReader);
            CustomCollection<TblProductStock> objCollection = ((CustomCollection<TblProductStock>)ExecuteReaderCmd(sqlCmd, reader));

            return objCollection;
        }


        public static int GetStockOutItemsCount(int stockLevel)
        {
            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBL_PRODUCTSTOCK_GET_PRODUCT_STOCK_BY_STOCK_LEVELPAGEDCOUNT);
            AddParameterToSqlCmd(sqlCmd, "@StockLevel", SqlDbType.Int, 0, ParameterDirection.Input, stockLevel);
            AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            ExecuteScalarCmd(sqlCmd);
            int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
            return returnValue;
        }

        private const string SP_TBL_PRODUCTSTOCK_GET_PRODUCT_STOCK_BY_PRODUCTID = "sp_TblProductStock_Get_ProductStock_By_ProductId";
        private const string SP_TBL_PRODUCTSTOCK_GET_PRODUCT_STOCK_BY_STOCK_LEVEL = "sp_TblProductStock_Get_ProductStock_By_Stock_Level";
        private const string SP_TBL_PRODUCTSTOCK_GET_PRODUCT_STOCK_BY_STOCK_LEVELPAGED = "sp_TblProductStock_Get_ProductStock_By_Stock_LevelPaged";
        private const string SP_TBL_PRODUCTSTOCK_GET_PRODUCT_STOCK_BY_STOCK_LEVELPAGEDCOUNT = "sp_TblProductStock_Get_ProductStock_By_Stock_LevelPagedCount";
        
    }
   
}
